package giit.computerbase.util;


import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.OperatingSystem;
import eu.bitwalker.useragentutils.UserAgent;

import java.util.HashMap;

/**
 * User: tum0r
 * Package Name: com.util
 * Time: 2018/10/30 Tuesday 15:17:47
 */
public class BrowserAnalysis {
    public static HashMap<String, String> analysis(String userAgent) {
        HashMap<String, String> result = new HashMap<>();
        UserAgent ua = UserAgent.parseUserAgentString(userAgent);
        Browser browser = ua.getBrowser();
        OperatingSystem operatingSystem = ua.getOperatingSystem();

        result.put("device", operatingSystem.getDeviceType().toString());
        result.put("os", operatingSystem.getName() + ";" + operatingSystem.getGroup() + ";" + operatingSystem.getManufacturer());
        result.put("browser", browser.getName() + ";" + ua.getBrowserVersion() + ";" + browser.getGroup() + ";" + browser.getManufacturer());
        return result;
    }
}
